package jcpcotizaciones.vista;

import java.sql.SQLException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import jcpcotizaciones.Control.ControlCotizacion;
import jcpcotizaciones.Control.ControlItem;
import jcpcotizaciones.Control.ControlOrdenProduccion_Item;
import jcpcotizaciones.Control.ControlOrden_Item;
import jcpcotizaciones.Modelo.Cliente;
import jcpcotizaciones.Modelo.Cotizacion;
import jcpcotizaciones.Modelo.Item;
import jcpcotizaciones.Modelo.OrdenItem;
import jcpcotizaciones.reportes.GenerarReporte;

/**
 * Darwin Silva Vargas
 * Viviana Figueroa Barros
 * Carlos Manota Mejía
 * Elkin Cedeño
 */

public class Buscar extends javax.swing.JFrame {


    public Buscar() {
        initComponents();
    }
    private String numOrden;
    private String fecha;
    private String hora;
    OrdenItem OI=new OrdenItem();
    DefaultTableModel dtmtablaitem = new DefaultTableModel();
    private vistaOrdenPedido vop;
    private vistaOrdenProduccion vopro;


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        piso_agregar = new jcMousePanel.jcMousePanel();
        jcMousePanel1 = new jcMousePanel.jcMousePanel();
        jLabel1 = new javax.swing.JLabel();
        tx_buscarcotizacion = new javax.swing.JTextField();
        bt_buscar = new javax.swing.JButton();
        jcMousePanel2 = new jcMousePanel.jcMousePanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tablaitem = new javax.swing.JTable(dtmtablaitem);
        jcMousePanel3 = new jcMousePanel.jcMousePanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        tx_codigo = new javax.swing.JTextField();
        tx_cedula = new javax.swing.JTextField();
        tx_nombre = new javax.swing.JTextField();
        tx_direccion = new javax.swing.JTextField();
        tx_telefono = new javax.swing.JTextField();
        tx_email = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jcMousePanel4 = new jcMousePanel.jcMousePanel();
        tx_total = new javax.swing.JTextField();
        tx_iva = new javax.swing.JTextField();
        tx_subtotal = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jcMousePanel5 = new jcMousePanel.jcMousePanel();
        bt_imprimir = new javax.swing.JButton();
        bt_salir = new javax.swing.JButton();
        bt_agregarPedido = new javax.swing.JButton();
        bt_agregarproduccion = new javax.swing.JButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(Buscar.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setAlwaysOnTop(true);
        setName("Form"); // NOI18N
        setResizable(false);

        piso_agregar.setIcon(resourceMap.getIcon("piso_agregar.icon")); // NOI18N
        piso_agregar.setMinimumSize(new java.awt.Dimension(770, 423));
        piso_agregar.setName("piso_agregar"); // NOI18N

        jcMousePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel1.border.titleFont"), resourceMap.getColor("jcMousePanel1.border.titleColor"))); // NOI18N
        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        tx_buscarcotizacion.setName("tx_buscarcotizacion"); // NOI18N
        tx_buscarcotizacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_buscarcotizacionActionPerformed(evt);
            }
        });

        bt_buscar.setIcon(resourceMap.getIcon("bt_buscar.icon")); // NOI18N
        bt_buscar.setText(resourceMap.getString("bt_buscar.text")); // NOI18N
        bt_buscar.setName("bt_buscar"); // NOI18N
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(10, 10, 10)
                .addComponent(tx_buscarcotizacion, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bt_buscar))
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tx_buscarcotizacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(bt_buscar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jcMousePanel2.setIcon(resourceMap.getIcon("jcMousePanel2.icon")); // NOI18N
        jcMousePanel2.setName("jcMousePanel2"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        dtmtablaitem.addColumn("Numero");
        dtmtablaitem.addColumn("Cantidad");
        dtmtablaitem.addColumn("Descripción");
        dtmtablaitem.addColumn("Tamaño");
        dtmtablaitem.addColumn("Papel");
        dtmtablaitem.addColumn("Tintas");
        dtmtablaitem.addColumn("Vr. Unitario");
        dtmtablaitem.addColumn("Vr. Total");
        tablaitem.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tablaitem.setName("tablaitem"); // NOI18N
        jScrollPane1.setViewportView(tablaitem);

        javax.swing.GroupLayout jcMousePanel2Layout = new javax.swing.GroupLayout(jcMousePanel2);
        jcMousePanel2.setLayout(jcMousePanel2Layout);
        jcMousePanel2Layout.setHorizontalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 439, Short.MAX_VALUE)
                .addContainerGap())
        );
        jcMousePanel2Layout.setVerticalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addContainerGap())
        );

        jcMousePanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel3.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel3.border.titleFont"), resourceMap.getColor("jcMousePanel3.border.titleColor"))); // NOI18N
        jcMousePanel3.setIcon(resourceMap.getIcon("jcMousePanel3.icon")); // NOI18N
        jcMousePanel3.setName("jcMousePanel3"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        tx_codigo.setEditable(false);
        tx_codigo.setName("tx_codigo"); // NOI18N

        tx_cedula.setEditable(false);
        tx_cedula.setName("tx_cedula"); // NOI18N

        tx_nombre.setEditable(false);
        tx_nombre.setName("tx_nombre"); // NOI18N

        tx_direccion.setEditable(false);
        tx_direccion.setName("tx_direccion"); // NOI18N

        tx_telefono.setEditable(false);
        tx_telefono.setName("tx_telefono"); // NOI18N

        tx_email.setEditable(false);
        tx_email.setName("tx_email"); // NOI18N

        javax.swing.GroupLayout jcMousePanel3Layout = new javax.swing.GroupLayout(jcMousePanel3);
        jcMousePanel3.setLayout(jcMousePanel3Layout);
        jcMousePanel3Layout.setHorizontalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jcMousePanel3Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(tx_codigo, javax.swing.GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE))
                    .addGroup(jcMousePanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(tx_direccion, javax.swing.GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE))
                    .addGroup(jcMousePanel3Layout.createSequentialGroup()
                        .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel5))
                        .addGap(18, 18, 18)
                        .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_nombre, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
                            .addComponent(tx_cedula, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)))
                    .addGroup(jcMousePanel3Layout.createSequentialGroup()
                        .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_email, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                            .addComponent(tx_telefono, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))))
                .addContainerGap())
        );
        jcMousePanel3Layout.setVerticalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel3Layout.createSequentialGroup()
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tx_cedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tx_direccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tx_telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(48, Short.MAX_VALUE))
        );

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jcMousePanel4.setIcon(resourceMap.getIcon("jcMousePanel4.icon")); // NOI18N
        jcMousePanel4.setName("jcMousePanel4"); // NOI18N

        javax.swing.GroupLayout jcMousePanel4Layout = new javax.swing.GroupLayout(jcMousePanel4);
        jcMousePanel4.setLayout(jcMousePanel4Layout);
        jcMousePanel4Layout.setHorizontalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 367, Short.MAX_VALUE)
        );
        jcMousePanel4Layout.setVerticalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 39, Short.MAX_VALUE)
        );

        tx_total.setEditable(false);
        tx_total.setText(resourceMap.getString("tx_total.text")); // NOI18N
        tx_total.setEnabled(false);
        tx_total.setName("tx_total"); // NOI18N

        tx_iva.setText(resourceMap.getString("tx_iva.text")); // NOI18N
        tx_iva.setEnabled(false);
        tx_iva.setName("tx_iva"); // NOI18N

        tx_subtotal.setText(resourceMap.getString("tx_subtotal.text")); // NOI18N
        tx_subtotal.setEnabled(false);
        tx_subtotal.setName("tx_subtotal"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jcMousePanel5.setIcon(resourceMap.getIcon("jcMousePanel5.icon")); // NOI18N
        jcMousePanel5.setMaximumSize(new java.awt.Dimension(461, 47));
        jcMousePanel5.setMinimumSize(new java.awt.Dimension(461, 47));
        jcMousePanel5.setName("jcMousePanel5"); // NOI18N

        bt_imprimir.setIcon(resourceMap.getIcon("bt_imprimir.icon")); // NOI18N
        bt_imprimir.setText(resourceMap.getString("bt_imprimir.text")); // NOI18N
        bt_imprimir.setEnabled(false);
        bt_imprimir.setName("bt_imprimir"); // NOI18N
        bt_imprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_imprimirActionPerformed(evt);
            }
        });

        bt_salir.setIcon(resourceMap.getIcon("bt_salir.icon")); // NOI18N
        bt_salir.setText(resourceMap.getString("bt_salir.text")); // NOI18N
        bt_salir.setName("bt_salir"); // NOI18N
        bt_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_salirActionPerformed(evt);
            }
        });

        bt_agregarPedido.setIcon(resourceMap.getIcon("bt_agregarPedido.icon")); // NOI18N
        bt_agregarPedido.setText(resourceMap.getString("bt_agregarPedido.text")); // NOI18N
        bt_agregarPedido.setName("bt_agregarPedido"); // NOI18N
        bt_agregarPedido.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarPedidoActionPerformed(evt);
            }
        });

        bt_agregarproduccion.setIcon(resourceMap.getIcon("bt_agregarproduccion.icon")); // NOI18N
        bt_agregarproduccion.setText(resourceMap.getString("bt_agregarproduccion.text")); // NOI18N
        bt_agregarproduccion.setName("bt_agregarproduccion"); // NOI18N
        bt_agregarproduccion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarproduccionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jcMousePanel5Layout = new javax.swing.GroupLayout(jcMousePanel5);
        jcMousePanel5.setLayout(jcMousePanel5Layout);
        jcMousePanel5Layout.setHorizontalGroup(
            jcMousePanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel5Layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(bt_imprimir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(bt_salir, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_agregarPedido)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_agregarproduccion)
                .addContainerGap(52, Short.MAX_VALUE))
        );
        jcMousePanel5Layout.setVerticalGroup(
            jcMousePanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jcMousePanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(bt_imprimir)
                    .addComponent(bt_salir)
                    .addComponent(bt_agregarPedido)
                    .addComponent(bt_agregarproduccion))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout piso_agregarLayout = new javax.swing.GroupLayout(piso_agregar);
        piso_agregar.setLayout(piso_agregarLayout);
        piso_agregarLayout.setHorizontalGroup(
            piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(piso_agregarLayout.createSequentialGroup()
                .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(piso_agregarLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, piso_agregarLayout.createSequentialGroup()
                                .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(piso_agregarLayout.createSequentialGroup()
                                        .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel9)
                                            .addComponent(tx_subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel10)
                                            .addComponent(tx_iva, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel11)
                                            .addComponent(tx_total, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jcMousePanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 459, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addGap(151, 151, 151)
                        .addComponent(jLabel2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        piso_agregarLayout.setVerticalGroup(
            piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(piso_agregarLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addGap(7, 7, 7))
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addComponent(jcMousePanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(piso_agregarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(piso_agregarLayout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tx_subtotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(piso_agregarLayout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tx_iva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(piso_agregarLayout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(tx_total, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcMousePanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(piso_agregarLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jcMousePanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(piso_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(piso_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
        buscarcotizacion();
}//GEN-LAST:event_bt_buscarActionPerformed

    private void bt_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_salirActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_bt_salirActionPerformed

    private void bt_agregarPedidoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarPedidoActionPerformed
        agregarItem();
    }//GEN-LAST:event_bt_agregarPedidoActionPerformed

    private void tx_buscarcotizacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_buscarcotizacionActionPerformed
        buscarcotizacion();
    }//GEN-LAST:event_tx_buscarcotizacionActionPerformed

    private void bt_imprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_imprimirActionPerformed
        imprimir();
    }//GEN-LAST:event_bt_imprimirActionPerformed

    private void bt_agregarproduccionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarproduccionActionPerformed
        agregarItemProduccion();
    }//GEN-LAST:event_bt_agregarproduccionActionPerformed

    public void imprimir()// este metodo solo funciana cuando hacemos visible la vista desde el boton buscar,
                          //porque después que la encontremos lo unico que podemos hacer es imprimir
    {
        if (tx_codigo.getText().equals("")){
          JOptionPane.showMessageDialog(null, "por favor primero busque una cotización");
         }else{
        GenerarReporte.generarReporteAbsoluto("C:\\reportes\\ReporCotizacion.jasper", tx_buscarcotizacion.getText(),"NumCotizacion");
         }
    }

        public void limpiar (){
            dtmtablaitem.setNumRows(0);
            tx_buscarcotizacion.setText("");
            tx_cedula.setText("");
            tx_codigo.setText("");
            tx_direccion.setText("");
            tx_email.setText("");
            tx_iva.setText("");
            tx_nombre.setText("");
            tx_subtotal.setText("");
            tx_telefono.setText("");
            tx_total.setText("");

        }


    public void agregarItem() // en este método agregamos item de la cotización a una orden de pedido.
    {
         try {
            OI.setFecha(fecha);
            OI.setHora(hora);
            OI.setNumOrden(numOrden);
            int x = tablaitem.getSelectedRow();
            String num = dtmtablaitem.getValueAt(x, 0).toString();
            OI.setNumItem(num);
            ControlOrden_Item.agregarOrden_Item(OI);
        } catch (SQLException ex) {
            Logger.getLogger(Buscar.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Buscar.class.getName()).log(Level.SEVERE, null, ex);
        }
       vop.listarItemPedido();
    }

        public void agregarItemProduccion() // en este método agregamos item de la cotización a una orden de pedido.
    {
         try {
            OI.setFecha(fecha);
            OI.setHora(hora);
            OI.setNumOrden(numOrden);
            int x = tablaitem.getSelectedRow();
            String num = dtmtablaitem.getValueAt(x, 0).toString();
            OI.setNumItem(num);
            ControlOrdenProduccion_Item.agregarOrden_Item(OI);
        } catch (SQLException ex) {
            Logger.getLogger(Buscar.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(Buscar.class.getName()).log(Level.SEVERE, null, ex);
        }
       vopro.listarItemProduccion();
    }

    public void buscarcotizacion(){ // Lo utilizamos para poder buscar cotización
                                  //la cotización a la cual le vamos a agregar los item.

          try {
            Cotizacion co = ControlCotizacion.BuscarCotizacion(tx_buscarcotizacion.getText());
            if(co!=null){
            Cliente cli = co.getCliente();
            bt_imprimir.setEnabled(true);
            tx_codigo.setText(cli.getCodigo());
            tx_cedula.setText(cli.getCedula());
            tx_nombre.setText(cli.getNombre());
            tx_direccion.setText(cli.getDireccion());
            tx_telefono.setText(cli.getTelefono());
            tx_email.setText(cli.getEmail());
            tx_subtotal.setText(Double.toString(co.getSubtotal()));
            tx_iva.setText(Double.toString(co.getIva()));
            tx_total.setText(Double.toString(co.getTotal()));

            }else{
               JOptionPane.showMessageDialog(null, "Esta cotización no existe");

            }
        } catch (SQLException ex) {
            Logger.getLogger(Buscar.class.getName()).log(Level.SEVERE, null, ex);
        }
        listarItem();

    }

  public void listarItem(){ // cada item que esté registrado a su vez va ha estar listado
                            //en una tabla en el formulario de la cotización.
        Item i = new Item();
        try {
            dtmtablaitem.setNumRows(0);
            ControlItem.listarItem();
            Iterator it = ControlItem.getItem().iterator();
                while (it.hasNext()) {
                    i = (Item) it.next();
                    if (i.getCotizacion().getNumero().equals(tx_buscarcotizacion.getText())){
                    String[] fila = {i.getNumero(), Integer.toString(i.getCantidad()), i.getDescripcion(), i.getCortepapel().getNombre(), i.getTipopapel().getNombre(),Integer.toString(i.getTiro())+"x"+ Integer.toString(i.getRetiro()), Double.toString(i.getValorunitario()), Double.toString(i.getValortotal())};
                    dtmtablaitem.addRow(fila);
                    }
                }
        } catch (SQLException ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCotizacion.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
  
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Buscar().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JButton bt_agregarPedido;
    public javax.swing.JButton bt_agregarproduccion;
    private javax.swing.JButton bt_buscar;
    public javax.swing.JButton bt_imprimir;
    public javax.swing.JButton bt_salir;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private jcMousePanel.jcMousePanel jcMousePanel2;
    private jcMousePanel.jcMousePanel jcMousePanel3;
    private jcMousePanel.jcMousePanel jcMousePanel4;
    private jcMousePanel.jcMousePanel jcMousePanel5;
    public static jcMousePanel.jcMousePanel piso_agregar;
    private javax.swing.JTable tablaitem;
    private javax.swing.JTextField tx_buscarcotizacion;
    private javax.swing.JTextField tx_cedula;
    private javax.swing.JTextField tx_codigo;
    private javax.swing.JTextField tx_direccion;
    private javax.swing.JTextField tx_email;
    private javax.swing.JTextField tx_iva;
    private javax.swing.JTextField tx_nombre;
    private javax.swing.JTextField tx_subtotal;
    private javax.swing.JTextField tx_telefono;
    private javax.swing.JTextField tx_total;
    // End of variables declaration//GEN-END:variables


    public String getNumOrden() {
        return numOrden;
    }
    public void setNumOrden(String numOrden) {
        this.numOrden = numOrden;
    }

    public String getFecha() {
        return fecha;
    }

    public void setFecha(String fecha) {
        this.fecha = fecha;
    }

    public String getHora() {
        return hora;
    }

    public void setHora(String hora) {
        this.hora = hora;
    }

    public vistaOrdenPedido getVop() {
        return vop;
    }

    public void setVop(vistaOrdenPedido vop) {
        this.vop = vop;
    }

    /**
     * @return the vopro
     */
    public vistaOrdenProduccion getVopro() {
        return vopro;
    }

    /**
     * @param vopro the vopro to set
     */
    public void setVopro(vistaOrdenProduccion vopro) {
        this.vopro = vopro;
    }

}
